<template>
    <div>
        <a-modal
         v-model:visible="visible" 
         :title="formState.id?formState.view?'查看':'编辑':'新增'" 
         @ok="handleOk" 
         @cancel="visible = false"
         class="enterprise-add-edit-modal"
         :width="700"
         :footer="null"
        >
            <div v-if="visible">
                <a-form :form="form" layout="horizontal" class="add-edit-form">
                    <a-form-item label="菌落数">
                        <a-input-number
                        style="width: 185px;"
                        :min="0"
                        :precision="0"
                        v-model:value="formState.fwswnd"
                        placeholder="请输入菌落数"
                        v-decorator="[
                            'fwswnd', { initialValue:formState.fwswnd, rules: rules.fwswnd}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="菌落类型">
                        <a-select
                            ref="select"
                            placeholder="请选择菌落类型"
                            v-model:value="formState.fjllx"
                            v-decorator="[
                                'fjllx', { initialValue:formState.fjllx, rules: rules.fjllx}
                            ]"
                            >
                            <a-select-option value="浮游菌">浮游菌</a-select-option>
                            <a-select-option value="沉降菌">沉降菌</a-select-option>
                        </a-select>
                    </a-form-item>
                    <a-form-item label="登记时间">
                        <a-date-picker
                        show-time
                        v-model:value="formState.fdjsj"
                        placeholder="请选择登记时间"
                        v-decorator="[
                            'fdjsj', { initialValue:formState.fdjsj, rules: rules.fdjsj}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="登记人">
                        <a-input
                        v-model:value="formState.fdjr"
                        placeholder="请输入登记人"
                        v-decorator="[
                            'fdjr', { initialValue:formState.fdjr, rules: rules.fdjr}
                        ]"/>
                    </a-form-item>
                </a-form>
            </div>
            <div style="
                display: flex; justify-content: flex-end;
                margin-top: 20px; width: 100%;
                background-color: #fff;">
                <a-button @click="visible = false">取消</a-button>
                <a-button style="margin-left: 10px;" v-if="!formState.view" class="blue-btn" type="primary" @click="handleOk(false)">确定</a-button>
            </div>
        </a-modal>
    </div>
</template>
<script>
import compSelector from '@/components/compSelector/compSelector.vue'
import { spcyQyInfoaddSccjHjjl } from '../service/index'
import moment from 'moment'
export default {
    components:{
        compSelector,
    },
    props:{

    },
    data(){
        return{
            visible:false,
            formState:{},
            form: this.$form.createForm(this, { name: 'coordinated' }),
            rules:{
                fwswnd: [{
                    type:'number',
                    required: true,
                    message: '请输入菌落数',
                    trigger: 'blur',
                }],
                fjllx: [{
                    required: true,
                    message: '请输入菌落类型',
                    trigger: 'blur',
                }],
                fdjsj: [{
                    type:'object',
                    required: true,
                    message: '请选择登记时间',
                    trigger: 'blur',
                }],
                fdjr: [{
                    required: true,
                    message: '请输入登记人',
                    trigger: 'blur',
                }],
            },
            materialUnitList:[],
        }
    },
    watch:{

    },
    mounted(){
    },
    methods:{
        getData(val){
            this.formState = {}
            this.formState = val
            this.formState.fdjsj = moment(this.formState.fdjsj)
        },
        handleOk(val){
            this.form.validateFields((err, values) => {
                if (!err) {
                    spcyQyInfoaddSccjHjjl({...this.formState,fdjsj:moment(this.formState.fdjsj).format("YYYY-MM-DD HH:mm:ss")}).then(res=>{
                        if(res.code == 200){
                            this.$message.success(res.message)
                            this.$emit('successAdd')
                            this.visible = false
                        }else{
                            this.$message.warning(res.message)
                        }
                    })
                    
                }
            })
        },
    }
}
</script>
<style lang="less">
.enterprise-add-edit-modal{
    .add-edit-form{
        display: flex;
        flex-wrap: wrap;
        .ant-form-item{
            display: flex;
        }
        .ant-form-item-label{
            width: 85px;
        }
        .ant-form-item-control-wrapper{
            width: 180px;
        }
        .flex-1-box{
            width: 100%;
            .ant-form-item-control-wrapper{
                flex: 1;
            }
        }
    }
}
</style>